package com.cn.springcloudshop.service.impl;

import com.cn.springcloudshop.mapper.YmShopOrderProductMapper;
import com.cn.springcloudshop.mapper.YmShopProductMapper;
import com.cn.springcloudshop.model.YmShopOrder;
import com.cn.springcloudshop.model.YmShopOrderProduct;
import com.cn.springcloudshop.model.YmShopOrderProductExample;
import com.cn.springcloudshop.model.YmShopProduct;
import com.cn.springcloudshop.service.inter.OrderProductService;
import com.sun.org.apache.regexp.internal.RE;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.Assert;

import java.util.List;

/**
 * @Author: wuyanzu
 * @Date: 2018/8/1
 */
@Service("OrderProductService")
@Transactional(rollbackFor = Exception.class)
public class OrderProductServiceImpl implements OrderProductService {

    @Autowired
    YmShopOrderProductMapper ymShopOrderProductMapper;

    @Override
    public int insert(Long productNum,Long orderId, YmShopProduct product,Long payType){
        Assert.notNull(orderId,"订单ID不能为空");
        Assert.notNull(product,"商品不能为空");
        YmShopOrderProduct ymShopOrderProduct = new YmShopOrderProduct();
        ymShopOrderProduct.setShopOrderId(orderId);
        ymShopOrderProduct.setShopProductNumber(productNum);
        ymShopOrderProduct.setShopProductId(product.getProductId());
        if (payType == 0) {
            ymShopOrderProduct.setShopProductPoint(product.getProductPoint());
            ymShopOrderProduct.setShopProductPrice(0L);
        } else if (payType == 1) {
            ymShopOrderProduct.setShopProductPrice(product.getProductPrice());
            ymShopOrderProduct.setShopProductPoint(product.getProductPoint());
        }
        Integer res = ymShopOrderProductMapper.insert(ymShopOrderProduct);
        return res == null ? 0 : res;
    }

    @Override
    public int insertSelective(YmShopOrderProduct record) {
        return 0;
    }

    @Override
    public List<YmShopOrderProduct> selectByExample(YmShopOrderProductExample example) {
        Assert.notNull(example, "订单和商品关联对象不能为空");
        return ymShopOrderProductMapper.selectByExample(example);
    }

    @Override
    public YmShopOrderProduct selectByPrimaryKey(Long id) {
        return null;
    }

    @Override
    public int updateByPrimaryKeySelective(YmShopOrderProduct record) {
        return 0;
    }

    @Override
    public int updateByPrimaryKey(YmShopOrderProduct record) {
        return 0;
    }

    @Override
    public int deleteByPrimaryKey(YmShopOrderProductExample example) {
        Assert.notNull(example,"参数不能为空");
        Integer res = ymShopOrderProductMapper.deleteByExample(example);
        return res == null ? 0 : res;
    }
}
